import urllib

class Download(object):
	def __init__(self, url, localFile):
		self.url = url
		try:
			self.file = urllib.urlopen(self.url)
			self.localFile = localFile
			self.getdownloadinformation()
			self.bytesread = 0
		except IOError:
			self.file = None
		
	def getdownloadinformation(self):
		if self.file:
			bytes = self.file.info().getheader('Content-Length')
			if bytes.isdigit():
				self.totalbytes = int(bytes)
			else:
				self.totalbytes = 0
		else:
			self.totalbytes = 0


"""
import urllib
from threading import Thread

#my files
#import download2
#my files
class ThreadDownload(Thread):
	def __init__(self, url, localFile):
		Thread.__init__(self)
		self.url = url
		try:
			self.file = urllib.urlopen(self.url)
			self.localFile = localFile
			self.getdownloadinformation()
			self.bytesread = 0
		except IOError:
			self.file = None
		
	def getdownloadinformation(self):
		if self.file:
			bytes = self.file.info().getheader('Content-Length')
			if bytes.isdigit():
				self.totalbytes = int(bytes)
			else:
				self.totalbytes = 0
		else:
			self.totalbytes = 0
		
	def run(self):
		if self.file:
			downloadfile = open(self.localFile, 'wb')			
			for line in self.file:
				self.bytesread += len(line)
				downloadfile.write(line)
				
			self.file.close()
			downloadfile.close()
"""